package oakclub.global;

import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.HashMap;
import java.util.Map;

public class DateFormatter
{
    public static ThreadLocal<Map<String, DateFormat>> tFormatters;

    static
    {
        tFormatters = new ThreadLocal<Map<String, java.text.DateFormat>>()
        {
            @Override
            protected Map<String, java.text.DateFormat> initialValue()
            {
                return new HashMap<>();
            }
        };
    }

    public static java.text.DateFormat getFormatter(String pattern)
    {
        Map<String, java.text.DateFormat> formatters = tFormatters.get();
        DateFormat formatter = formatters.get(pattern);
        if(formatter == null)
        {
            formatter = new SimpleDateFormat(pattern);
            formatters.put(pattern, formatter);
        }
        return formatter;
    }
}
